use std::io;

fn main() -> io::Result<()> {
    // Create a new TUN interface named "tun0" in TUN mode.
    let nic = tun_tap::Iface::new("tun0", tun_tap::Mode::Tun)?;

    // Define a buffer of size 1504 bytes (maximum Ethernet frame size without CRC) to store received data.
    let mut buf = [0u8; 1504];

    // Main loop to continuously receive data from the interface.
    loop {
        // Receive data from the TUN interface and store the number of bytes received in `nbytes`.
        let nbytes = nic.recv(&mut buf[..])?;

        let flags = u16::from_be_bytes([buf[0], buf[1]]); 
        let proto = u16::from_be_bytes([buf[2], buf[3]]); 

        eprint!("flag {:#b} proto {:#b} :\n", flags, proto);
        eprint!("read {}    bytes: {:02x?}\n", nbytes - 4, &buf[4..nbytes]);


        // parse tcp   
    }

    Ok(())
}

